package com.xw.userService.utils;


import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.ResourceUtils;

/**
 * 文件读取工具类
 * @author xiaoshengda
 *
 * @date 创建时间：2017年10月18日 上午10:12:57
 */
public class FileUtil {
	private static final Logger LOG = LoggerFactory.getLogger(FileUtil.class);
	public static String readFile(String url) throws IOException {
		String fileContent = "";
		try {
			
			File file = ResourceUtils.getFile(url);
			if (file.isFile() && file.exists()) {
				InputStreamReader read = new InputStreamReader(new FileInputStream(file), "utf-8");
				BufferedReader reader = new BufferedReader(read);
				String line;
				while ((line = reader.readLine()) != null) {
					fileContent += line;
				}
				read.close();
			}

		} catch (FileNotFoundException e) {
			LOG.error("文件读取异常", e);
			e.printStackTrace();
			
		}
		 return fileContent;   
	}

}
